package controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;

import entity.User;
import entity.UserForIns;
import entity.UserForUpd;

@Controller
@RequestMapping("/user")
@Api(value = "User", description = "user service api", position = 2)
public class UserController {
	@RequestMapping(value = "/{userId}", method = RequestMethod.GET)
	@ApiOperation(httpMethod = "GET", nickname="getUser", value = "get user by userId", response = User.class)
	public @ResponseBody User getUser(@PathVariable String userId, HttpServletRequest request) {
		User u = new User();
		u.setUserId(userId);
		u.setUserName("swagger");
		return u;
	}
	
	@RequestMapping(value = "/", method = RequestMethod.POST)
	public @ResponseBody User insertUser(@RequestBody UserForIns user) {
		User u = new User();
		u.setUserId(user.getUserId());
		u.setUserName(user.getUserName());
		u.setAge(user.getAge());
		u.setSex(user.getSex());
		return u;
	}
	
	@RequestMapping(value = "/{userId}", method = RequestMethod.PATCH)
	public @ResponseBody User updateUser(@RequestBody UserForIns user) {
		User u = new User();
		u.setUserId(user.getUserId());
		u.setUserName(user.getUserName());
		u.setAge(user.getAge());
		u.setSex(user.getSex());
		return u;
	}
}
